首页
首页

Docker存储驱动 devicemapper 的配置方法

Docker存储驱动 devicemapper 的配置方法

首先需要说明:

1
2
3
系统内核在3.18建议选择overlayfs driver方式

但是系统内核在3.18之前的版本那么只能使用device-mapper driver方式,或者升级系统内核

本文主要来说devicemapper的配置方法与使用方法

devicemapper是Centos系统下Docker Engine的默认存储驱动,它有两种配置模式:loop-lvm和direct-lvm,Centos安装后模式使用的时候loop-lvm模式,但是通过docker info可以看到官方会有个一个提醒

WARNING: Usage of loopback devices is strongly discouraged for production use. Either use --storage-opt dm.thinpooldev or use --storage-opt dm.no_warn_on_loop_devices=true to suppress this warning.

网上很多做法推荐正式环境是采用 –storage-opt dm.thinpooldev or use –storage-opt dm.no_warn_on_loop_devices=true 的方式隐藏该警告,这种做法只是简单的隐藏了,看着好看而已,没解决实际问题

本文主要是教大家使用devicemapper的direct-lvm模式

1、 停止docker

1
systemctl stop docker

2、添加一个硬盘,或者外部存储

这边添加了一块20G  /dev/sdb

3、创建PV

1
2
3
4
5
6
7
# pvcreate /dev/sdb

返回

[root@localhost ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created.
[root@localhost ~]#

4、创建VG

1
2
3
4
5
6
7
# vgcreate docker /dev/sdb

返回

[root@localhost ~]# vgcreate docker /dev/sdb
Volume group "docker" successfully created
[root@localhost ~]#

5、查看VG信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
    # vgdisplay docker

返回信息

[root@localhost ~]# vgdisplay docker
--- Volume group ---
VG Name docker
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 20.00 GiB
PE Size 4.00 MiB
Total PE 5119
Alloc PE / Size 0 / 0
Free PE / Size 5119 / 20.00 GiB
VG UUID vR1VrC-MrQv-KtaE-RIse-2dZh-i67Q-Y0d9x1
``
6、创建thinpool

1)、创建pool
# lvcreate --wipesignatures y -n thinpool docker -l 95%VG

返回信息

[root@localhost ~]# lvcreate --wipesignatures y -n thinpool docker -l 95%VG
  Logical volume "thinpool" created.
[root@localhost ~]# 

# lvcreate --wipesignatures y -n thinpoolmeta docker -l 1%VG

返回信息

[root@localhost ~]# lvcreate --wipesignatures y -n thinpoolmeta docker -l 1%VG
  Logical volume "thinpoolmeta" created.
[root@localhost ~]# 

说明: 数据LV大小为VG的95%,元数据LV大小为VG的1%,剩余的空间用来自动扩展。
1
2)、将pool转换为thinpool
# lvconvert -y --zero n -c 512K --thinpool docker/thinpool --poolmetadata docker/thinpoolmeta

返回信息

[root@localhost ~]# lvconvert -y --zero n -c 512K --thinpool docker/thinpool --poolmetadata docker/thinpoolmeta
  WARNING: Converting logical volume docker/thinpool and docker/thinpoolmeta to thin pool's data and metadata volumes with metadata wiping.
  THIS WILL DESTROY CONTENT OF LOGICAL VOLUME (filesystem etc.)
  Converted docker/thinpool to thin pool.
[root@localhost ~]# 
1
2
3
7、配置thinpool

1、)配置池的自动扩展
创建 docker-thinpool.profile

# vim /etc/lvm/profile/docker-thinpool.profile

添加:

activation {

    thin_pool_autoextend_threshold=80

    thin_pool_autoextend_percent=20

}
1
2、)应用配置变更
# lvchange --metadataprofile docker-thinpool docker/thinpool

返回信息

[root@localhost ~]# lvchange --metadataprofile docker-thinpool docker/thinpool
  Logical volume docker/thinpool changed.
[root@localhost ~]# 
1
3、)状态监控检查
# lvs -o+seg_monitor

返回信息

[root@localhost ~]# lvs -o+seg_monitor
  thinpool docker twi-a-t--- 19.00g             0.00   0.03                             monitored
[root@localhost ~]# 
1
8、配置Docker服务并启动
vim /usr/lib/systemd/system/docker.service 
1
添加以下参数:
--storage-driver=devicemapper --storage-opt=dm.thinpooldev=/dev/mapper/docker-thinpool --storage-opt dm.use_deferred_removal=true --storage-opt dm.use_deferred_deletion=true --storage-opt dm.basesize=30G
1
参数作用
--storage-driver=devicemapper  使用什么存储驱动
--storage-opt=dm.thinpooldev=/dev/mapper/docker-thinpool  存储到哪里
--storage-opt dm.use_deferred_removal=true --storage-opt dm dm.use_deferred_deletion=true  官方说:unintentionally leaking mount points 不明白具体意思
--storage-opt dm.basesize=30G 设置每个容器最大使用空间
1
删除old文件
# rm -rf /var/lib/docker/*
1
重启服务
systemctl restart docker
1
9、查看信息
docker info

Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 1.10.3
Storage Driver: devicemapper
 Pool Name: docker-thinpool
 Pool Blocksize: 524.3 kB
 Base Device Size: 32.21 GB
 Backing Filesystem: xfs
 Data file: 
 Metadata file: 
 Data Space Used: 25.69 MB
 Data Space Total: 20.4 GB
 Data Space Available: 20.37 GB
 Metadata Space Used: 61.44 kB
 Metadata Space Total: 213.9 MB
 Metadata Space Available: 213.8 MB
 Udev Sync Supported: true
 Deferred Removal Enabled: true
 Deferred Deletion Enabled: true
 Deferred Deleted Device Count: 0
 Library Version: 1.02.135-RHEL7 (2016-09-28)
Execution Driver: native-0.2
Logging Driver: journald
Plugins: 
 Volume: local
 Network: host bridge null
Kernel Version: 3.10.0-514.2.2.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
Number of Docker Hooks: 2
CPUs: 1
Total Memory: 976.5 MiB
Name: localhost.localdomain
ID: GBCE:CKUJ:VGTS:GSLS:4QEI:PH2O:BDI4:GYM2:OEMX:T7PF:3ZOF:5O5F
Registries: docker.io (secure)

``

其他相关:

lvs 查看thinpool 使用情况
1
2
3
4
5
6
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- 17.47g
swap centos -wi-ao---- 2.00g
thinpool docker twi-a-t--- 19.00g 0.13 0.03
[root@localhost ~]#

5月2日更新:

docker 在更新后配置文件目录变成/etc/sysconfig/docker

因此以上第8部修改成为:

1
2
3
vim /etc/sysconfig/docker
``
添加
--storage-driver=devicemapper --storage-opt=dm.thinpooldev=/dev/mapper/docker-thinpool --storage-opt dm.use_deferred_removal=true --storage-opt dm.use_deferred_deletion=true --storage-opt dm.basesize=30G
1

OPTIONS=‘ --selinux-enabled --log-driver=journald --signature-verification=false'
1
2
3
中。

变成:
OPTIONS='--storage-driver=devicemapper --storage-opt=dm.thinpooldev=/dev/mapper/docker-thinpool --storage-opt dm.use_deferred_removal=true --storage-opt dm.use_deferred_deletion=true --storage-opt dm.basesize=30G --selinux-enabled --log-driver=journald --signature-verification=false'
End 
支持一下
扫一扫,我会更有动力更新
  • 微信扫一扫
  • 支付宝扫一扫